﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using AssetManageSystem.Model.AssetManage;


namespace AssetManageSystem.ViewModel.AssetManage.AssetScrapVMs
{
    public partial class AssetScrapListVM : BasePagedListVM<AssetScrap_View, AssetScrapSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-green"),
                this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-blue"),
                this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-8"),
                // this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-orange"),
                this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "AssetManage", dialogWidth: 800).SetButtonClass("layui-bg-red"),
                // this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "AssetManage", dialogWidth: 800).SetButtonClass("btn-col-4"),
                this.MakeStandardAction("AssetScrap", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], "AssetManage").SetButtonClass("btn-col-4"),
            };
        }


        protected override IEnumerable<IGridColumn<AssetScrap_View>> InitGridHeader()
        {
            return new List<GridColumn<AssetScrap_View>>{
                this.MakeGridHeader(x => x.DocNumber),
                this.MakeGridHeader(x => x.OutDate),
                this.MakeGridHeader(x => x.AsName_view),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<AssetScrap_View> GetSearchQuery()
        {
            var query = DC.Set<AssetScrap>()
                .CheckContain(Searcher.DocNumber, x=>x.DocNumber)
                .CheckBetween(Searcher.OutDate?.GetStartTime(), Searcher.OutDate?.GetEndTime(), x => x.OutDate, includeMax: false)
                .CheckWhere(Searcher.SelectedAssetIdIDs,x=>DC.Set<AssetScrapMiddleTable>().Where(y=>Searcher.SelectedAssetIdIDs.Contains(y.AssetId)).Select(z=>z.AssetScrapId).Contains(x.ID))
                .Select(x => new AssetScrap_View
                {
				    ID = x.ID,
                    DocNumber = x.DocNumber,
                    OutDate = x.OutDate,
                    AsName_view = x.AssetId.Where(y=>y.Asset.IsValid==true).Select(y=>y.Asset.AsName).ToSepratedString(null,","), 
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class AssetScrap_View : AssetScrap{
        [Display(Name = "资产名称")]
        public String AsName_view { get; set; }

    }
}
